uniform sampler2D tex;
varying vec3 normal;
varying vec3 lightDir;
varying vec3 eyeVec;       //Direction of the line of sight

void main(void) {
    vec4 Am = gl_FrontMaterial.ambient * texture2D(tex, gl_TexCoord[0].st);
    vec4 Dm = gl_FrontMaterial.diffuse * texture2D(tex, gl_TexCoord[0].st);
    //vec4 Sm = gl_FrontMaterial.specular;

    normal = normalize(normal);
    lightDir = normalize(lightDir);
    vec3 reflection = reflect(-lightDir, normal);
    float lambertTerm = dot(normal, lightDir);

    //float specularIntensity = 0;

    //if(lambertTerm > 0.0) {
    //    specularIntensity = pow(max(dot(reflection, eyeVec), 0.0), gl_FrontMaterial.shininess);
    //}

    vec4 ambient = Am*gl_LightSource[0].ambient + Am*gl_LightModel.ambient;
    vec4 diffuse = Dm*gl_LightSource[0].diffuse*lambertTerm;
    //vec4 specular = Sm*gl_LightSource[0].specular*specularIntensity;

    vec4 fogColour = vec4(0.3, 0.3, 0.3, 1.0);
    float z = gl_FragCoord.z / gl_FragCoord.w;
    float fogFactor = exp(-0.003*z);
    fogFactor = clamp(fogFactor, 0.0, 1.0);
    gl_FragColor = mix(fogColour, ambient+diffuse, fogFactor);
}
